/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evangelion.core.daoImpl;

import com.evangelion.core.bean.Declaracion;
import com.evangelion.core.dao.DeclaracionDao;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Kellycasma
 */
@Repository
public class DeclaracionDaoImpl extends GenericDaoImpl<Serializable> implements DeclaracionDao {

    @Override
    public List<Declaracion> listDeclaraciones(String tipo) {
        em = getEntityManager();
        Query q = em.createQuery("SELECT a from Declaracion a WHERE a.tipo=:tipo");
        q.setParameter("tipo", "Facturacion");
        return q.getResultList();
    }

    @Override
    public Declaracion findDeclaracionByannoTrim(int anno, int trimestre) {
        em = getEntityManager();
        Query q = em.createQuery("SELECT a from Declaracion a WHERE a.anno=:anno and a.trimestre=:trimestre AND a.tipo=:tipo");
        q.setParameter("anno", anno);
        q.setParameter("trimestre", trimestre);
        q.setParameter("tipo", "Facturacion");
        try {
            return (Declaracion) q.getSingleResult();
        } catch (Exception e) {
            return null;
        }

    }
}
